<title>Macros</title>
<head>
<script language="JavaScript">
</script>
</head>
<body bgcolor="#ffffcc">
<hr>
<center>
<h1>Macros</h1>
</center>
<hr>
<p>
Macros are built on the <a href="define_preprocessor.html">#define</a> 
preprocessor.<p>
Normally a #define would look like:
<pre>
	#define PI 3.142
</pre>
But, a macro would look like this.
<pre>
	#define SQUARE(x) x*x
</pre>
The main difference is that the first example is a constant and the second 
is an expression. 
If the <b>macro</b> above was used in some code it may look like this:
<pre>
        #define SQUARE(x)  x*x

        main()
        {
          int value=3;
          printf("%d \n", SQUARE(value));
        }
</pre>
After preprocessing the code would become:
<pre>
        main()
        {
          int value=3;
          printf("%d \n", value*value);
        }
</pre>
<hr>
<h2>Examples:</h2>

<a href="../EXAMPLES/macro.c"><img src="../../GRAPHICS/computer.gif"></a>
macro example.<p>
<hr>
<h2>Notes:</h2>
<ul>
<li>The value passed to SQUARE could have been an 
<a href="../CONCEPT/data_types.html#int">int</a>
<a href="../CONCEPT/data_types.html#float">float</a>
or
<a href="../CONCEPT/data_types.html#double">double</a>
<li>Long macros can span multiple lines by using a 
<a href="../FUNCTIONS/escape.html">\</a> followed by a newline
(return).
<li>If you are using gcc to compile your code, you can use the -E option to
see the preprocessor output 
</ul>
<hr>
<h2>See Also:</h2>
<ul>
<li><A href="define_preprocessor.html">#define</a> preprocessor.
<font color=brown>
<li><A href="../../CPLUSPLUS/SYNTAX/inline.html">inline</a> A C++ keyword that provides a better aproch to macros.
</font>
</ul>


<p>

<hr>
<p>
<center>
<table border=2 width="80%" bgcolor="ivory">
<tr align=center>
<td width="25%">
<a href="../cref.html">                  Top</a>
</td><td width="25%">
<a href="../master_index.html">          Master Index</a>
</td><td width="25%">
<a href="keywords.html">                 Keywords</a>
</td><td width="25%">
<a href="../FUNCTIONS/funcref.htm">      Functions</a>
</td>
</tr>
</table>
</center>
<p>
<hr>
<address><a href="../../address.html">Martin Leslie</a> 
</address><p>
</body>
</html>
